class AgentTeamStaticController{
    constructor($state,$scope,$rootScope,AccountService,AgentService){
        Object.assign(this,{$state,$scope,$rootScope,AccountService,AgentService});
        let currentState = $state.$current.name;
        let self = this;
        this.dateFormat = "YYYY-MM-DD";
        this.start_date =moment().subtract(9, 'day').format( this.dateFormat);
        this.end_date = moment().format( this.dateFormat);
        this.$scope.daterange1=this.start_date +' → ' + this.end_date;
        this.init();
        this.getTeamStatic(this.start_date,this.end_date);

    }

    init(){
        let self = this;
        //日期时间范围
        laydate.render({
               elem: '#teamstaticForm_daterange'
               ,range: '→'
           });
    }

    search(){
        let self = this;
        let dateRangString = $("#teamstaticForm_daterange")[0].value;
        this.$scope.daterange1=dateRangString;
        if(dateRangString){
            let pieces =   dateRangString.split('→');
            let startDateStr = pieces[0].trim();
            let endDateStr = pieces[1].trim();
            this.getTeamStatic(startDateStr,endDateStr);
        }
    }

    getTeamStatic(start_date,end_date){
        let self  = this;
        let param = {};
        param.start_date= start_date;
        param.end_date= end_date;
        let startDateMoment = moment(start_date, self.dateFormat);
        let endDateMoment = moment(end_date,self.dateFormat);
        let count = endDateMoment.diff(startDateMoment,"days");
        let labelDateArray = new Array();
        labelDateArray.push(startDateMoment.format("MM-DD"));
        for(let i=0;i<count;i++){
            labelDateArray.push(startDateMoment.add(1,"days").format("MM-DD"));
        }
        self.$scope.labels = labelDateArray;
        self.AgentService.getTeamStatic(param).then(_success).catch(_error);
        function _success(data) {

            self.$scope.teamStaticResult = data;
            let team_charge_amount_array = new Array();
            let team_withdrow_amount_array = new Array();
            let team_bet_order_amount_array = new Array();
            let bet_user_count_array = new Array();
            let reg_user_count_array = new Array();
            let login_user_count_array = new Array();
            for (let i=0;i<data.data.length;i++){
                let item =data.data[i];
                team_charge_amount_array.push(item.team_charge_amount);
                team_withdrow_amount_array.push(item.team_withdrow_amount);
                team_bet_order_amount_array.push(item.team_bet_order_amount);
                bet_user_count_array.push(item.bet_user_count);
                reg_user_count_array.push(item.reg_user_count);
                login_user_count_array.push(item.login_user_count);
            }
            self.$scope.data = [
                team_charge_amount_array,
                team_withdrow_amount_array,
                team_bet_order_amount_array,
                bet_user_count_array,
                reg_user_count_array,
                login_user_count_array,
            ];
            self.$scope.onClick = function (points, evt) {
                console.log(points, evt);
            };
            self.$scope.datasetOverride = [{ yAxisID: 'y-axis-1' }, { yAxisID: 'y-axis-2' }];
            self.$scope.series = ['团队充值', '团队提款', '团队投注', '注册人数', '投注人数', '登录人数'];
            self.$scope.options = {
                scales: {
                    yAxes: [
                        {
                            id: 'y-axis-1',
                            type: 'linear',
                            display: true,
                            position: 'left'
                        },
                        {
                            id: 'y-axis-2',
                            type: 'linear',
                            display: true,
                            position: 'right'
                        }
                    ]
                }
            };
        }
        function _error(reason) {
            console.log(`AgentTeamStaticController.getTeamStatic(): ${reason}`);
        }
    }
}
AgentTeamStaticController.$inject = ["$state","$scope","$rootScope","AccountService","AgentService"];

export default AgentTeamStaticController;